package com.xgkj.diyiketang.weidget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.MeasureSpec;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.xgkj.diyiketang.R;

public class MyCustomListView extends ListView{
	private View mFootView;
	private ProgressBar mFootProgress;
	private TextView mFootText;
	private Context mContext;

	public MyCustomListView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		mContext = context;
		init();
	}

	public MyCustomListView(Context context, AttributeSet attrs) {
		super(context, attrs);
		mContext = context;
		init();
	}

	public MyCustomListView(Context context) {
		super(context);
		mContext = context;
		init();
	}
	
	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		// TODO Auto-generated method stub
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,  
	            MeasureSpec.AT_MOST);  
	    super.onMeasure(widthMeasureSpec, expandSpec);
	}
	
	public void init(){
		mFootView = LayoutInflater.from(mContext).inflate(R.layout.foot_moreloading, null);
		mFootProgress = (ProgressBar) mFootView.findViewById(R.id.foot_progress);
		mFootText = (TextView) mFootView.findViewById(R.id.foot_text);
		mFootProgress.setVisibility(View.GONE);
		addFooterView(mFootView);
	}
	
	public void setNoNextPage(){
		if(getFooterViewsCount() == 0){
			addFooterView(mFootView);
		}
		mFootView.setVisibility(View.VISIBLE);
		mFootProgress.setVisibility(View.GONE);
		mFootText.setText(R.string.no_next_page);
	}

}
